<?php

namespace app\common\command;


use app\common\model\Member;
use app\common\model\MemberAccount;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class AutoMobile extends Command
{
    protected function configure()
    {
        $this->setName('AutoMobile')
            ->setDescription('Say Hello');
    }

    protected function execute(Input $input, Output $output)
    {
        $members = Member::query()->select();
        $num = rand(1, 5);
        $arr = array_rand($members->toArray(), $num);
        foreach ($arr as $index) {
            $this->insertAccount($members[$index]);
        }
        $output->writeln("Success ");
    }


    protected function insertAccount($member)
    {
        $change = rand(2, 20) * 100;
        MemberAccount::insert([
            'member_id' => $member['id'],
            'money_before' => $change,
            'money_now' => 0,
            'money_change' => $change,
            'money_all' => $change * rand(10, 20),
            'money_consume' => 0,
            'money_frozen' => 0,
            'type' => MemberAccount::TypeWithdraw,
            'status' => MemberAccount::StatusSuccess,
            'create_time' => time() - rand(0, 60),
            'update_time' => time() - rand(0, 60),
        ]);
    }


}